﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Chroniker
{
    public partial class Menu : Form
    {
        #region Variables
        private Color color = Color.DarkOrange;
        #endregion

        #region Events
        public event EventHandler ToggleRun;
        protected virtual void OnToggleRun(EventArgs e) { ToggleRun(this, e); }
        #endregion

        public Menu() { 
            InitializeComponent();
        }

        #region Event Handlers
        /// <summary>
        /// Browse button handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnBrowse_Click(object sender, EventArgs e) {
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            dialog.SelectedPath = txtLogPath.Text.Trim();
            DialogResult result = dialog.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK)
                this.txtLogPath.Text = dialog.SelectedPath;
        }
        /// <summary>
        /// Color choice button handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnColor_Click(object sender, EventArgs e) {
            ColorDialog dialog = new ColorDialog();
            DialogResult result = dialog.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK) {
                pTitle.BackColor = dialog.Color;
                this.color = dialog.Color;
            }
        }
        /// <summary>
        /// Save settings
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOk_Click(object sender, EventArgs e) {
            Properties.Settings.Default.Color = this.color;
            Properties.Settings.Default.Logging = chkLogging.Checked;
            Properties.Settings.Default.LogPath = txtLogPath.Text.Trim();
            Properties.Settings.Default.Timeout = Convert.ToInt32(this.nudTimeout.Value);
            Properties.Settings.Default.Save();

            this.Hide(); 
        }
        /// <summary>
        /// Pause/Resume button handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPause_Click(object sender, EventArgs e) {
            if (btnPause.Text == "Pause") { btnPause.Text = "Resume"; }
            else { btnPause.Text = "Pause"; }

            OnToggleRun(e);
        }
        /// <summary>
        /// Menu options showing
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Menu_Showing(object sender, EventArgs e) {
            this.color = Properties.Settings.Default.Color;
            this.ForeColor = color;
            pTitle.BackColor = color;
            nudTimeout.ForeColor = color;
            txtLogPath.ForeColor = color;

            chkLogging.Checked = Properties.Settings.Default.Logging;
            this.txtLogPath.Text = Properties.Settings.Default.LogPath;
            nudTimeout.Value = Properties.Settings.Default.Timeout;
        }
        /// <summary>
        /// Set colors for controls
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pTitle_BackChanged(object sender, EventArgs e) {
            this.ForeColor = pTitle.BackColor;
            this.nudTimeout.ForeColor = pTitle.BackColor;
            this.txtLogPath.ForeColor = pTitle.BackColor;
        }
        #endregion

    }
}
